**********************************************************************************************
* Reproduces Figures 7
*
* Cloyne, Dimsdale and Hürtgen (2024) 								
*	"Are Tax Cuts Contractionary at the Zero Lower Bound? Evidence from a Century of Data"  	  		
*																			
* James Cloyne, Nicholas Dimsdale and Patrick Hürtgen, 2024
**********************************************************************************************


global outputfolder = "${rootfolder}/StateDep"
capture mkdir ${outputfolder}
global outputfolder = "${outputfolder}/${figure}"
capture mkdir ${outputfolder}

* control set specification
capture macro drop controlist 
capture macro drop controlist1 controlist2


*---------------------------------------------------------*
*-------------------- Setup --------------------*
*---------------------------------------------------------*

global approach = "LP"
global LHS = "raw"

* Sample harmonization
global harmonized = 0


* ---------- LP regression --------------- *
global qLags = 4  // lags for Tax shocks
global pLags = 4  // lags for controls
global gLags = 0  // lags for government spending shock controls
global hmax = ${hmax} + 1

global controlist lnRealGDP lnRealTaxRev lnRealExp BankRate RealRate 		

/* -------------  Baseline LP ------------ */

use ${datapath}/${DataSetName},clear

foreach y in RealRate  {
	
	preserve 
	global depvar = "`y'"

	do ${dofilepath}/LP_DataTransform_LR.do

	local labely : variable label $depvar
	local yname = subinstr("`labely'"," ","",.)
	local filename = "S_`yname'ToTax_${LHS}" 

	if $skipsample == 1 {
		local filename = "`filename'_s"  
	}
	
	log close _all 

	log using ${outputfolder}/`filename', name(StateDep_ZLB_${depvar}) text replace

	do ${dofilepath}/LP_IRFs_StateDep.do
	
	if $PlotIRF == 1 & $saveFigs == 1 {

		forv j = 0/1 {
			gr export "${outputfolder}/IRF_`filename'_Regime`j'.pdf", name(IRF_`yname'_`j') replace
			
		}
	}
	
	keep Quarters b0 b1 u${alpha2}* d${alpha2}* u${alpha1}* d${alpha1}*
	drop if Quarters == .
	
	ren b0 point_NoZLB
	ren b1 point_ZLB
	ren u${alpha2}0 u${alpha2}_NoZLB
	ren u${alpha2}1 u${alpha2}_ZLB
	ren u${alpha1}0 u${alpha1}_NoZLB
	ren u${alpha1}1 u${alpha1}_ZLB
	ren d${alpha2}0 d${alpha2}_NoZLB
	ren d${alpha2}1 d${alpha2}_ZLB
	ren d${alpha1}0 d${alpha1}_NoZLB
	ren d${alpha1}1 d${alpha1}_ZLB
	
	save "${outputfolder}/DataIRF_`filename'_`y'_${LHS}.dta", replace
	export excel "${outputfolder}/DataIRF_`filename'_`y'_${LHS}.xlsx", firstrow(variables)  keepcellfmt replace

	log close _all
	restore
}

global hmax = 13




